package com.hh.test.design.prototype;

import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.io.Serializable;
import java.util.List;

public class Teacher implements Cloneable, Serializable {
	/**
	 * 
	 */
	private static final long serialVersionUID = -5696814639608081100L;
	private String name;
	private List<Student> list;

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public List<Student> getList() {
		return list;
	}

	public void setList(List<Student> list) {
		this.list = list;
	}

	@Override
	protected Teacher clone() throws CloneNotSupportedException {

		try {
			ByteArrayOutputStream out = new ByteArrayOutputStream();
			ObjectOutputStream objOut;
			objOut = new ObjectOutputStream(out);
			objOut.writeObject(this);

			ByteArrayInputStream input = new ByteArrayInputStream(
					out.toByteArray());
			ObjectInputStream inputObj = new ObjectInputStream(input);
			return (Teacher) inputObj.readObject();

		} catch (IOException e) {
			e.printStackTrace();
		} catch (ClassNotFoundException e) {
			e.printStackTrace();
		}

		return (Teacher) super.clone();
	}

	@Override
	public String toString() {
		return "Teacher [name=" + name + ", list=" + list + "]";
	}

}
